const express = require("express")
const axios = require("axios")
const app = express()

const port = 5002


app.use((req, res, next)=>{
  console.log("有人请求服务器了！")
  next()
})


app.get('/cars', (req, res)=>{
  const cars = [
    {id: '001', name:"日产骐达", price: 29900},
    {id: '002', name:"本田思域", price: 39900},
    {id: '003', name:"奇瑞瑞虎8pro", price: 119900},
    {id: '004', name:"奥迪", price: 490000},
  ]
  res.send(cars)
})


app.listen(port, "localhost", (err) => {
  if (!err){
  	console.log("服务器启动成功")
  	console.log(`请求github真实数据请访问：http://localhost:${port}/cars`)
  } 
  else console.log(err);
})
